//
//  my.swift
//  WaterTownCharm
//
//  Created by 今安在 on 2024/3/24.
//

import SwiftUI

struct my: View {
    
    @State var isPro : Bool = false
    
    var body: some View {
        
        NavigationView{
            List{
                myInformationView()
                HStack{
                    Spacer()
                    iconsUnderMyInformationView(iconsName: "heart.fill",textName: "喜欢",iconsColor: .pink)
                    Spacer()
                    iconsUnderMyInformationView(iconsName: "star.fill",textName: "收藏",iconsColor: .yellow)
                    Spacer()
                    iconsUnderMyInformationView(iconsName: "creditcard.fill",textName: "订单",iconsColor: .green)
                    Spacer()
                    iconsUnderMyInformationView(iconsName: "clock",textName: "足迹",iconsColor: .purple)
                    Spacer()
                }
                Section{
                    middleNavigationView(labelName: "设置", systemImageName: "gear", destinationName: ProgressView())
                    middleNavigationView(labelName: "关于", systemImageName: "info.circle", destinationName: ProgressView())
                    middleNavigationView(labelName: "帮助", systemImageName: "questionmark.circle", destinationName: ProgressView())
                }
                
                Section{
                    HStack {
                        Text("升级PRO版 去广告")
                            .foregroundColor(.red)
                        Spacer()
                        Toggle(isOn: $isPro, label: {
                            
                        })
                        .labelsHidden()
                        .alert(isPresented: $isPro){
                            Alert(title: Text("请支付¥6"),
                                  message: Text("支付宝账号18368326181"),
                                  primaryButton: .default(Text("好的")),
                                  secondaryButton: .cancel(Text("取消"))
                            )
                        }
                    }
                }
                shareContentView(
                    urlName: "https://www.douyin.com/user/MS4wLjABAAAA-n3PdwwzqrWEgJQwDj4x4c-w2gZn9PnBQkKRH0oxLg8",
                    labelName: "@官方抖音号",
                    iconsName: "music.note",
                    iconsName2: "plus.square.on.square"
                )
                shareContentView(
                    urlName: "http://www.wuzhen.com.cn",
                    labelName: "@官方网站",
                    iconsName: "safari",
                    iconsName2: "link"
                )
                shareContentView(
                    urlName: "https://mp.weixin.qq.com/s?__biz=MzA4MDc0MDkxMw==&mid=2650499146&idx=2&sn=5943f96ac373ee612190b188843a66ed&chksm=87905f14b0e7d602b70ec3a1613c22302c6c23fd37e6fbef5079dcd2de6bc679fc4778e635f8&scene=27",
                    labelName: "@官方微信公众号",
                    iconsName: "message.badge",
                    iconsName2: "plus.message"
                )
                shareContentView(
                    urlName: "http://www.wuzhen.com.cn/web/poto/opinion",
                    labelName: "@官方邮件",
                    iconsName: "envelope",
                    iconsName2: "square.and.pencil"
                )
            }
            .navigationTitle("我的")
            
        }
    }
}

#Preview {
    my()
}

struct myInformationView: View {
    var body: some View {
        VStack (spacing : 8){
            Image(systemName: "person.crop.circle.badge.checkmark")
                .symbolVariant(.circle.fill)
                .font(.system(size: 32))
                .symbolRenderingMode(.palette)
                .foregroundStyle(.blue , .blue.opacity(0.5))
                .padding()
                .background(Circle().fill(.ultraThinMaterial))
                .background(
                    BlobView()
                        .offset(x: 200, y: 0)
                        .scaleEffect(0.6)
                )
                .background(
                    HexagonView()
                        .offset(x: -50, y: -100)
                )
            
            Text("今安在")
                .font(.title.weight(.semibold))
            HStack {
                Image(systemName: "location.fill")
                    .imageScale(.small)
                    .foregroundColor(.pink)
                Text("浙江 嘉兴")
                    .foregroundColor(.secondary)
            }
        }
        
        
        .frame(maxWidth: .infinity)
        .padding()
    }
}


struct iconsUnderMyInformationView: View {
    @State var iconsName : String
    @State var textName : String
    @State var iconsColor : Color
    
    var body: some View {
        VStack{
            Image(systemName: iconsName)
                .font(.largeTitle)
                .foregroundColor(iconsColor)
                .frame(width: 75, height: 35)
            Text(textName)
                .font(.body)
                .fontWeight(.light)
                .foregroundColor(.black)
        }
        .padding(.top)
    }
}

struct middleNavigationView<Destination: View>: View{
    
    @State var labelName : String
    @State var systemImageName : String
    @State var destinationName : Destination
    
    var body: some View {
        NavigationLink(destination: destinationName){
            Label(labelName,systemImage: systemImageName)
        }
    }
}

struct shareContentView: View {
    @State var urlName : String
    @State var labelName : String
    @State var iconsName : String
    @State var iconsName2 : String
    var body: some View {
        Link(destination: URL(string: urlName)!){
            HStack {
                Label(labelName, systemImage: iconsName)
                Spacer()
                Image(systemName: iconsName2)
                    .foregroundColor(.secondary)
            }
        }
    }
}
